package com.heima.controller;

import com.github.pagehelper.Page;
import com.heima.dto.NewsAuthDto;
import com.heima.dto.WmNewsDto;
import com.heima.dto.WmNewsPageReqDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.entity.WmNews;
import com.heima.service.WmNewsService;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 自媒体文章表(WmNews)表控制层
 *
 * @author makejava
 * @since 2022-04-12 15:35:29
 */
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    /**
     * 服务对象
     */
    @Resource
    private WmNewsService wmNewsService;

    /**
     * 分页查询
     *
     * @param wmNews 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
/*    @GetMapping
    public ResponseEntity<Page<WmNews>> queryByPage(WmNews wmNews, PageRequest pageRequest) {
        return ResponseEntity.ok(this.wmNewsService.queryByPage(wmNews, pageRequest));
    }*/

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    /*@GetMapping("{id}")
    public ResponseEntity<WmNews> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.wmNewsService.queryById(id));
    }*/

    /**
     * 新增数据
     *
     * @param wmNews 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<WmNews> add(WmNews wmNews) {
        return ResponseEntity.ok(this.wmNewsService.insert(wmNews));
    }

    /**
     * 编辑数据
     *
     * @param wmNews 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<WmNews> edit(WmNews wmNews) {
        return ResponseEntity.ok(this.wmNewsService.update(wmNews));
    }


    /**
     * 根据ID删除文章
     * @param newsId
     * @return
     */
    @GetMapping(path = "/del_news/{newsId}")
    public ResponseResult deleteById(@PathVariable("newsId") Long newsId) {

        return wmNewsService.deleteById(newsId);
    }
    /**
     *编辑 查询单个文章详情
     * @param newsId
     * @return
     */
   /* @GetMapping(path = "/one/{newsId}")
    public ResponseResult one(@PathVariable("newsId") Long newsId) {
        WmNews wmNews = wmNewsService.queryById(newsId);
        return ResponseResult.okResult(wmNews);
    }*/
    /**
     *编辑 查询单个文章详情
     * @param id
     * @return
     * admin
     */
    @GetMapping(path = "/one_vo/{id}")
    public ResponseResult one1(@PathVariable("id") Long id) {
        NewsAuthDto newsAuthDto = wmNewsService.queryById(id);

        return ResponseResult.okResult(newsAuthDto);
    }
    /**
     *
     * 添加数据信息
     * @param dto
     * @return
     */
    @PostMapping("submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {

        return wmNewsService.submit(dto);
    }
    /**
     * 查询文章列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.list(dto);
    }
    /**
     * 查询文章列表
     * @param dto
     * @return
     * admin
     */
    @PostMapping("/list_vo")
    public ResponseResult list1(@RequestBody NewsAuthDto dto) {
        return wmNewsService.list1(dto);
    }
    /**
     * 审核失败
     * @param
     * @return
     * admin
     */
    @PostMapping("auth_fail")
    public ResponseResult fail(@RequestBody NewsAuthDto dto){
       wmNewsService.fail(dto);
        return ResponseResult.okResult("审核失败");

    }
    /**
     * 审核成功
     * @param
     * @return
     * admin
     */
    @PostMapping("auth_pass")
    public ResponseResult pass(@RequestBody NewsAuthDto dto){
        wmNewsService.pass(dto);
        return ResponseResult.okResult("审核成功");

    }
}

